package org.example.nio_demo;

import org.junit.Test;

import java.io.Serializable;
import java.nio.channels.FileChannel;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

/**
 * @ClassName DemoChannel3
 * @Description
 * @Author zhangsw
 * @Date 2020/11/9 23:14
 * @Version 1.0
 */
public class DemoChannel3 {
    public static void main(String[] args) throws Exception {
        long startTime = System.currentTimeMillis();//2281-2541-2633
        //通道之间的数据传输(直接缓冲区)
        FileChannel inChannel = FileChannel.open(Paths.get("D:\\Users\\zhangsw\\Desktop\\Learn\\a.zip"), StandardOpenOption.READ);
        FileChannel outChannel = FileChannel.open(Paths.get("D:\\Users\\zhangsw\\Desktop\\Learn\\b.zip"),
                StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE);

        //数据传输
//        inChannel.transferTo(0, inChannel.size(), outChannel);
        outChannel.transferFrom(inChannel, 0, inChannel.size());

        inChannel.close();
        outChannel.close();
        long endTime = System.currentTimeMillis();
        System.err.println(endTime - startTime);
    }

}
